package com.leaf.u_spring.chapter07;

import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.springframework.web.WebApplicationInitializer;

public class ServletAndFiterInit implements WebApplicationInitializer {

	@Override
	public void onStartup(ServletContext servletContext) throws ServletException {
		// 注册映射Servlet
		javax.servlet.ServletRegistration.Dynamic appServlet = servletContext.addServlet("appServlet", AppServlet.class);
		appServlet.addMapping("/app/**");
		
		//配置StandardServletMultipartResolver接受请求的路径tmp/upload，文件大小不超过20M，整个请求不超过40M
		appServlet.setMultipartConfig(new MultipartConfigElement("tmp/upload", 2097152, 4194304, 0));
		
		//注册映射Filter
		javax.servlet.FilterRegistration.Dynamic appFilter = servletContext.addFilter("appFilter", AppFilter.class);
		appFilter.addMappingForUrlPatterns(null, false, "/app/**");
		
		
	}

}
